package com.leyou.item.service;

import com.leyou.item.entity.TbSpecGroup;
import com.leyou.item.entity.TbSpecParam;
import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecService {

    @Autowired
    private SpecGroupMapper specGroupMapper;

    @Autowired
    private SpecParamMapper specParamMapper;

    /*查询获得分组信息*/
    public List<TbSpecGroup> querySepcGroupsWithParamsByCid(Long cid){
        TbSpecGroup tbSpecGroup1 = new TbSpecGroup();
        tbSpecGroup1.setCid(cid);
        List<TbSpecGroup> groups = specGroupMapper.select(tbSpecGroup1);
        groups.forEach(group->{
            List<TbSpecParam> params = this.queryParams(group.getId(), null, null, null);
            group.setParams(params);
        });

        return groups;
    }
    /*添加组信息*/
    public void addSpecGroup(TbSpecGroup group){
        specGroupMapper.insertSelective(group);
    }
    /*修改组信息*/
    public void updateSpecGroup(TbSpecGroup group){
        specGroupMapper.updateByPrimaryKeySelective(group);
    }
    /*删除组信息*/
    public void deleteSpecGroup(Long id){
        specGroupMapper.deleteByPrimaryKey(id);
    }

    /*
    *
    * 参数信息
    *
    * */
    /*查询参数信息*/
    public List<TbSpecParam> queryParams(Long gid, Long cid, Boolean searching,Boolean generic){
        TbSpecParam tbSpecParam = new TbSpecParam();
        tbSpecParam.setGroupId(gid);
        tbSpecParam.setCid(cid);
        tbSpecParam.setSearching(searching);
        tbSpecParam.setGeneric(generic);
        return specParamMapper.select(tbSpecParam);
    }
    /*添加参数信息*/
    public void addParam(TbSpecParam param){
        specParamMapper.insertSelective(param);
    }
    /*修改参数信息*/
    public void updateParam(TbSpecParam param){
        specParamMapper.updateByPrimaryKeySelective(param);
    }
    /*删除参数信息*/
    public void deleteParam(Long id){
        specParamMapper.deleteByPrimaryKey(id);
    }




}
